package dao;

import java.util.List;

import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import entity.Hebergement;

@Stateless
@Local
public class HebergementDaoJpa implements HebergementDao {

	private EntityManager entityManager;

	@PersistenceContext(unitName = "MyPersistentUnit")
	public void setEntityManager(EntityManager entityManager) {
		this.entityManager = entityManager;
	}

	public EntityManager getEntityManager() {
		return entityManager;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Hebergement> getAllHebergements() {
		Query query = entityManager.createQuery("select h from Hebergement as h");
		List<Hebergement> listeHebergement = query.getResultList();
		return listeHebergement;
	}

	@Override
	public Hebergement getHebergementById(long id) {
		Hebergement h = entityManager.find(Hebergement.class, id);
		return h;
	}

}
